package com.easpeed.user.dialog

import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import com.blankj.utilcode.util.ScreenUtils
import com.easpeed.comon.memorycache.CommonMemoryCache
import com.easpeed.comon.utils.DownloadHelper
import com.easpeed.elevator.R
import com.easpeed.elevator.utils.NoticeDialog

/**
 * Created by bigyu on 2024/10/30 20:14
 * com.easpeed.user.dialog
 */
object UserDialogHelper {
@JvmStatic
@JvmOverloads

    fun showNoticeDialog(mContext: Context, title: String, content: String, sureClick: (() -> Unit)? = null, cancelClick: (() -> Unit)? = null) {
        val dialog: NoticeDialog = NoticeDialog.Builder(mContext).setLayoutId(R.layout.user_dialog_exit).setClickBtnDismissDialog(true).setDialogWidth(CommonMemoryCache.getDialogMaxWidth()).setOnclickListener(R.id.sure, View.OnClickListener { v: View? ->
            sureClick?.let { it() }
        }).setOnclickListener(R.id.cancel, View.OnClickListener { v: View? ->
            cancelClick?.let { it() }
        }).create()
        if (mContext is Activity) {
            if (mContext.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                dialog.setDialogWith((ScreenUtils.getScreenWidth() * 0.5f).toInt())

            } else {
            }
        } else {
        }
        dialog.setGravity(Gravity.CENTER)
        dialog.setText(R.id.title, title)
        dialog.setText(R.id.content, content)

        dialog.show()
    }

    @JvmStatic
    @JvmOverloads
    fun showDownloadDialog(mContext: Context, title: String, content: String, sureClick: ((dialog: NoticeDialog?) -> Unit)? = null, cancelClick: (() -> Unit)? = null) {
        var dialog: NoticeDialog? = null

        dialog = NoticeDialog.Builder(mContext).setLayoutId(R.layout.dialog_download).setCanceledOnTouchOutside(false).setClickBtnDismissDialog(false).setDialogWidth(CommonMemoryCache.getDialogMaxWidth()).setOnclickListener(R.id.sure, View.OnClickListener { v: View? ->
            sureClick?.let { it(dialog) }
        }).setOnclickListener(R.id.cancel, View.OnClickListener { v: View? ->
            cancelClick?.let { it() }

            dialog?.dismiss()
        }).create()
        dialog.setText(R.id.title, title)

        dialog.setGravity(Gravity.CENTER)
        dialog.show()
    }

    fun showImageDialog(mContext: Context, imageBitmap: Bitmap?, sureClick: (() -> Unit)? = null, cancelClick: (() -> Unit)? = null) {
        if (imageBitmap == null) {
            return
        }
        val dialog: NoticeDialog = NoticeDialog.Builder(mContext).setLayoutId(R.layout.user_dialog_image).setClickBtnDismissDialog(true).setDimAmount(1f).create()
        dialog.setDialogWith(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight())

        dialog.getViewT<ImageView>(R.id.image).setImageBitmap(imageBitmap)
        dialog.setGravity(Gravity.CENTER)
        dialog.show()
    }
}